/***************************************************************
Made by: Cultured::Labs

Copyright (c) 2011 Cultured::Labs
****************************************************************/
#include "battle.h"

bool battle(Spaceship player, Spaceship opponent) {
  //gets requiered hits
  int player_rhits = (opponent.get_hp() + opponent.get_armor()) / player.get_damage();
  int opponent_rhits =  (player.get_hp() + player.get_armor()) / opponent.get_damage();
  std::cout << player_rhits << "      " << opponent_rhits << std::endl << std::endl;

  srand((unsigned)time(0));
  int random_index = rand() % 2;
  std::cout << "Index: " << random_index << std::endl;

  if (random_index == 0) player_rhits--;
  if (random_index == 1) opponent_rhits--;

  std::cout << player_rhits << "      " << opponent_rhits << std::endl << std::endl;

  bool player_win = false;
  if (player_rhits < opponent_rhits) player_win = true;

  //output
  std::cout << player.get_title() << " vs " << opponent.get_title() << '\n' << std::endl;
  return player_win;
}
